package ct.zxd.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ct.zxd.db.Dao;
import ct.zxd.db.OrderDao;

/**
 * Servlet implementation class UpdateOrderFromWX
 */
public class UpdateOrderFromWX extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("UTF-8");
        response.setContentType("text/xml;character=utf-8");  
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter writer = response.getWriter();

        String statusStr = request.getParameter("status");
        String idString = request.getParameter("orderid");
        int status = 0, orderid;
        
        
        try {
        	orderid = Integer.parseInt(idString);
        	OrderDao dao = new OrderDao();
        	
        	int count = 0;
			if(statusStr != null){
				status = Integer.parseInt(statusStr);
				count = dao.updateOrderStatus(orderid, "1", status);
			}else{
				count = dao.deleteOrder(orderid, "1");
			}				
			if(count<=0){
				writer.write("杯具，数据库出错");
			}else {
				writer.write("操作成功");
			}
        	
		} catch (Exception e) {
			e.printStackTrace();
			writer.write("杯具，服务器出错");
		}
	
	
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
